//
//  PlayerTopView.swift
//

import UIKit

class PlayerTopView: UIView {
    
    var didClose: () -> Void = {}
    var didLock: () -> Void = {}
    var didForScreen: () -> Void = {}
    
    var isShow: Bool = false {
        didSet {
            if isShow {
                UIView.animate(withDuration: 0.25, animations: {
                    self.transform = CGAffineTransform(translationX: 0, y: -50.fit)
                    self.alpha = 0
                }) { _ in}
            } else {
                transform = CGAffineTransform(translationX: 0, y: -50.fit)
                UIView.animate(withDuration: 0.25) {
                    self.alpha = 1
                    self.transform = .identity
                }
            }
        }
    }
    
    private lazy var closeBtn: UIButton = {
        let view = UIButton()
        view.setImage("video_back_blue".image, for: .normal)
        view.addTarget(self, action: #selector(closeBtnClick), for: .touchUpInside)
        return view
    }()
    
    lazy var lockBtn: UIButton = {
        let view = UIButton()
        view.setImage("video_lock_blue".image, for: .normal)
        view.addTarget(self, action: #selector(lockBtnClick), for: .touchUpInside)
        return view
    }()
    
    lazy var forScreenBtn: UIButton = {
        let view = UIButton()
        view.setImage("video_tv_blue".image, for: .normal)
        return view
    }()
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        backgroundColor = UIColor.black.alpha(0.1)
        addSubview(closeBtn)
        addSubview(lockBtn)
        addSubview(forScreenBtn)
        
        closeBtn.snp.makeConstraints { (make) in
            make.centerY.equalToSuperview()
            make.left.equalToSuperview().offset(12)
            make.size.equalTo(CGSize(width: 46.fit, height: 46.fit))
        }
        
        lockBtn.snp.makeConstraints { (make) in
            make.centerY.equalToSuperview()
            make.right.equalToSuperview().offset(-10)
            make.size.equalTo(CGSize(width: 40.fit, height: 40.fit))
        }
        
        forScreenBtn.snp.makeConstraints { (make) in
            make.centerY.equalToSuperview()
            make.right.equalTo(lockBtn.snp.left).offset(-10)
            make.size.equalTo(CGSize(width: 40.fit, height: 40.fit))
        }
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    @objc private func closeBtnClick() {
        didClose()
    }
    
    @objc private func lockBtnClick() {
        didLock()
    }
}
